package transport

import (
	"fmt"
)

type PacketReadFunc func([]byte)

type Transport interface {
	Open() error
	Write(b []byte) (int, error)
	Close()
}

func NewTransport(network, host string, port int, readFunc PacketReadFunc) (Transport, error) {
	var transport Transport
	switch network {
	case "udp", "udp4":
		transport = NewClientUDP(host, port, readFunc)
	case "tcp", "tcp4":
		transport = NewClientTCP(host, port, readFunc)
	default:
		return nil, fmt.Errorf("un support network. %v", network)
	}

	return transport, nil
}
